SRC_DIR = src
BUILD_DIR = build

PREFIX = .
DOCS_DIR = ${PREFIX}/docs
TEST_DIR = ${PREFIX}/test
DIST_DIR = ${PREFIX}/dist
APIS_DIR = ${SRC_DIR}/apis
PLUG_DIR = ${SRC_DIR}/plugins

BASE_FILES = ${SRC_DIR}/core.js\
	${SRC_DIR}/ajax.js\
	${SRC_DIR}/request.js\
	${SRC_DIR}/dialog.js\
	${SRC_DIR}/oauth.js\

APIS = ${APIS_DIR}/contacts.js

PLUGINS = ${PLUG_DIR}/testPlugin.js

DAPPR_MODULES = ${SRC_DIR}/intro.js\
           	  ${BASE_FILES}\
           	  ${PLUGINS}\
           	  ${APIS}\
        	${SRC_DIR}/outro.js\
        	${SRC_DIR}/json2.js\

DP = ${DIST_DIR}/dappr.js
DP_MIN = ${DIST_DIR}/dappr.min.js

DP_VER = `cat version.txt`
VER = sed s/@VERSION/${DP_VER}/

MINJAR = java -jar ${BUILD_DIR}/google-compiler-20091218.jar

DATE=`svn info . | grep Date: | sed 's/.*: //g'`
REV=`svn info . | grep Rev: | sed 's/.*: //g'`

all: dappr min
	@@echo "Dappr.js build complete."

${DIST_DIR}:
	@@mkdir -p ${DIST_DIR}

dappr: ${DIST_DIR} ${DP}

${DP}: ${DAPPR_MODULES}
	@@echo "Building" ${DP}

	@@mkdir -p ${DIST_DIR}
	@@cat ${DAPPR_MODULES} | \
		sed 's/Date:./&'"${DATE}"'/' | \
		sed 's/Revision:./&'"${REV}"'/' | \
		${VER} > ${DP};

	@@echo ${DP} "Built"
	@@echo

min: ${DP_MIN}

${DP_MIN}: ${DP}
	@@echo "Building" ${DP_MIN}
 
	@@head -9 ${DP} > ${DP_MIN}
	@@${MINJAR} --js ${DP} --warning_level QUIET >> ${DP_MIN}

	@@echo ${DP_MIN} "Built"
	@@echo

test: ${DP}
	@@echo "Test Suite not yet available"

runtest: ${DP} test
	@@echo

clean:
	@@echo "Removing Distribution directory:" ${DIST_DIR}
	@@rm -rf ${DIST_DIR}

	@@echo "Removing Documentation directory:" ${DOCS_DIR}
	@@rm -rf ${DOCS_DIR}

